This section illustrates use of the Scheme debug procedure in an
extended session. The first example is the buggy fact procedure
that was used as an example in section above. The
sequence begins with the interaction already described in
section
.
The command S displays the current subproblem. The command
B moves backwards in time.
The F command moves forward through reductions one at a time, in
the opposite direction to B.
We are now back at the subproblem level containing the offending
expression. The variable L is unbound. The Z (for ZAP) command
asks for an expression to evaluate and returns this value as the
value of the current subproblem to the previous subproblem, that is,
the containing subproblem. Here we wanted L to be 1.
And here is the correct result. Let's look at another example:
Above is a square root program that is divided into
sub-procedures. In the program there is a bug. The debugger was
called to reveal that the unbound variable ASN is in the expression
(* ans asn) in the procedure CLOSE?.
Here is another example:
The bug here is that the procedure EVEN? was spelled EVIN?, in the definition of the procedure TERM-PROC. By looking at the history we can see that the procedure SUM was called somewhere at subproblem 4. The command G used below goes to a specified subproblem and reduction. Below we see the call to SUM in subproblem 4, reduction 4.
The environment in which subproblem 4 was being evaluated is the
user-initial-environment. The C command displayes the variable
bindings in the evaluation environment of the current subproblem.
Which in this case is the user-initial-environment. This is where
evin? should be defined. The V command evaluates an expression in
the current environment.
Above we defined the variable evin? to have as its value the procedure even?. We then left the debugger. By typing (proceed) at the error prompt we cause the program to continue with the evaluation of the expression that caused the error, and the procedure completes returning the correct answer.